package com.lollipop.rabbitmq.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author: Lollipop
 * @Date: 2021-10-03 12:49
 * @Description: 连接RabbitMQ工具类
 */
public class RabbitMqUtiils {
    public static Channel getChannel() throws IOException, TimeoutException {
        // 从连接工厂获取连接
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.247.129");
        connectionFactory.setUsername("lollipop");
        connectionFactory.setPassword(("lollipop"));
        Connection connection = connectionFactory.newConnection();
        // 由连接获取信道
        Channel channel = connection.createChannel();
        return channel;
    }
}
